package com.hex.ds.hdtp.core.inf.data.configuration.repository.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hex.ds.hdtp.core.inf.common.page.Page;
import com.hex.ds.hdtp.core.inf.common.page.converter.IPageAndMyBatisPlusPageConverter;
import com.hex.ds.hdtp.core.inf.data.configuration.mapper.ITableConvertMapper;
import com.hex.ds.hdtp.core.inf.data.configuration.po.TableConvertPo;
import com.hex.ds.hdtp.core.inf.data.configuration.repository.ITableConvertRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Package com.hex.ds.hdtp.core.inf.preparation.repository.Impl
 * @ClassName ConvertRepository
 * @Description 转换配置-数据服务接口实现类
 * @Author yh.wan
 * @Date 2023/8/7 16:10
 * @Version v1.0
 **/
@Component
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class TableConvertRepository implements ITableConvertRepository {

    private final ITableConvertMapper convertMapper;

    private final IPageAndMyBatisPlusPageConverter pageConverter;

    /**
     * @Method: queryListByPage
     * @Param: [toPo, toPage]
     * @Return: com.hex.ds.hdtp.core.inf.common.page.Page<com.hex.ds.hdtp.core.inf.preparation.po.ConvertPo>
     * @Description: 分页查询
     * @Author yh.wan
     * @Date 2023/8/7 16:10
     * @Version v1.0
     **/
    @Override
    public Page<TableConvertPo> queryListByPage(TableConvertPo toPo, Page toPage) {
        final IPage tmpPageResult = convertMapper.queryListByPage(
                pageConverter.toMyBatisPlusPage(toPage)
                , toPo
        );
        final List list = tmpPageResult.getRecords();
        final Page pageResult = pageConverter.toPage(tmpPageResult);
        return pageResult.setData(list);
    }

    /**
     * @Method: queryList <br>
     * @Param: [convertPo] <br>
     * @Return: java.util.List<com.hex.ds.hdtp.core.inf.preparation.po.ConvertPo> <br>
     * @Description：不分页查询<br>
     * @Author yh.wan
     * @Date 2023/8/7 16:10
     * @Version v1.0
     **/
    @Override
    public List<TableConvertPo> queryList(TableConvertPo convertPo) {
        return convertMapper.queryList(convertPo);
    }

    /**
     * @Method: queryById
     * @Param: [pkId]
     * @Return: com.hex.ds.hdtp.core.inf.preparation.po.ConvertPo
     * @Description: 单个查询
     * @Author yh.wan
     * @Date 2023/8/7 16:10
     * @Version v1.0
     **/
    @Override
    public TableConvertPo queryById(String pkId) {
        return convertMapper.selectById(pkId);
    }

    /**
     * @Method: add
     * @Param: [convertPo]
     * @Return: java.lang.Integer
     * @Description: 新增
     * @Author yh.wan
     * @Date 2023/8/7 16:10
     * @Version v1.0
     **/
    @Override
    public Integer add(TableConvertPo convertPo) {
        return convertMapper.insert(convertPo);
    }

    /**
     * @Method: modifyById
     * @Param: [convertPo]
     * @Return: java.lang.Integer
     * @Description: 修改
     * @Author yh.wan
     * @Date 2023/8/7 16:10
     * @Version v1.0
     **/
    @Override
    public Integer modifyById(TableConvertPo convertPo) {
        return convertMapper.updateById(convertPo);
    }

    /**
     * @Method: removeById
     * @Param: [pkId]
     * @Return: java.lang.Integer
     * @Description: 删除
     * @Author yh.wan
     * @Date 2023/8/7 16:10
     * @Version v1.0
     **/
    @Override
    public Integer removeById(String pkId) {
        return convertMapper.deleteById(pkId);
    }

}
